<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <span>上传头像</span>
    <form action="/photo/get" method="post" id="f1" enctype="multipart/form-data">
        <input type="file" id="jpgfile" name="jpgfile">
        <input type="text" id="username" name="username">
    </form>
    <button type="submit" id="submit">点击提交</button>
    <img src="/photo/upload" id="image">
</body>
<script>
    $("#submit").click(
        function (){
            // var files = $('#jpgfile').prop('files');
            // var data = new FormData();
            // console.log(data)
            // data.append('jpgfile', files[0]);
            var form = document.getElementById("f1");
            var file = new FormData(form);
            $.ajax({
                type: 'POST',
                url: "/photo/get",
                data: file,
                cache: false,
                processData: false,
                contentType: false,
                success: function (result){
                    alert(result);
                }
            });
        }

    );

</script>
</html>